package com.ebupt.migu.music.effectStatistics.service.Impl;

import com.ebupt.migu.music.common.entity.Page;
import com.ebupt.migu.music.common.entity.ResultObject;
import com.ebupt.migu.music.common.util.ExcelUtils;
import com.ebupt.migu.music.common.util.ReqestParamUtil;
import com.ebupt.migu.music.common.util.excelSheet.Sheet;
import com.ebupt.migu.music.effectStatistics.entity.vo.MessageExportVo;
import com.ebupt.migu.music.effectStatistics.mapper.MessageNoticeMapper;
import com.ebupt.migu.music.effectStatistics.service.MessageNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author xuhongsong@cd.ebupt.com
 * @version 1.0
 * @className MessageNoticeServiceImpl
 * @date 2020/7/6 16:09
 */
@Service("messageNoticeService")
public class MessageNoticeServiceImpl implements MessageNoticeService {

    // 消息通知mapper接口
    @Autowired
    private MessageNoticeMapper messageNoticeMapper;

    /**
     * 分页查询
     *
     * @param params
     * @return
     */
    @Override
    public ResultObject queryMap(Map<String, Object> params) {
        ResultObject<Page<HashMap<String, Object>>> res = new ResultObject<>();
        // 是否系统管理员 1-系统管理员； 0-普通用户；
        String is_admin = params.get("isAdmin").toString();
        if ("1".equals(is_admin) || "1".equals(params.get("isSuperAdmin"))){//是否超级管理员
            params.remove("creatorDepartment");
        }
        // 判断是查询明细还是汇总
        String summary = params.get("summary").toString();
        // 总数
        Integer total = "1".equals(summary) ? messageNoticeMapper.countSummary(params) : messageNoticeMapper.countQuery(params);
        // 分页查询结果集
        List<HashMap<String, Object>> datas = "1".equals(summary) ? messageNoticeMapper.querySummary(params) : messageNoticeMapper.queryMap(params);
        // 分页
        Page<HashMap<String, Object>> page = new Page<>();
        page.setTotal(total);
        page.setData(datas);
        res.setData(page);
        return res;
    }






    /**
     * 导出
     *
     * @param params
     * @return
     */
    @Override
    public List<MessageExportVo> exportMap(Map<String, Object> params) {
        // 是否超级管理员 1-超级管理员； 0-普通用户；
        String is_admin = params.get("isAdmin").toString();
        if ("1".equals(is_admin)) {
            params.remove("creatorDepartment");
        }
        // 判断是查询明细还是汇总
        String summary = params.get("summary").toString();
        List<MessageExportVo> datas = "1".equals(summary) ? messageNoticeMapper.exportSummary(params) : messageNoticeMapper.exportMap(params);
        return datas;
    }


    /**
     *   详情列表  没有分页
     * @param params
     * @return
     */
    @Override
    public List<HashMap<String, Object>> turnOverList(Map<String, Object> params){
        return messageNoticeMapper.turnOverList(params);
    };




    /**
     * 目标人群
     * @param params
     * @return
     */
    @Override
    public ResultObject targetUser(Map<String, Object> params){
        ResultObject<List<HashMap<String, Object>>> res = new ResultObject<>();
        // 是否超级管理员 1-超级管理员； 0-普通用户；
        String is_admin = params.get("isAdmin").toString();
        if ("1".equals(is_admin)){
            params.remove("creatorDepartment");
        }
        List<HashMap<String, Object>> list = messageNoticeMapper.targetUser();
        res.setMsg("success");
        res.setData(list);
        return res;
    };
}
